<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // sort
    var arr = [
      { name: '小明', age: 0 },
      { name: '大白', age: 18 },
      { name: '怂孩儿', age: 8 }
    ];

    function compare(property) {
      return function (a, b) {
        var value1 = a[property];
        var value2 = b[property];
        return value1 - value2;
      }
    }
    console.log(arr.sort(compare('age')))

    // localCompare
    string.localCompare(target, locals)
    var str1 = 'beijing',
      str2 = '北京',
      str3 = '背景',
      str4 = '北方';

    str1.localecompare(str2);    //1
    str2.localecompare(str3);    //1
    str3.localecompare(str2);    //-1
    str4.localecompare(str2);    //-1
    str4.localecompare(str3);    //-1

  </script>
</body>

</html>